package maven.jyhs.com.servlet;



import com.alibaba.fastjson2.JSON;
import maven.jyhs.com.entity.Sea;
import maven.jyhs.com.proxy.dynamic.CglibProxyFactory;
import maven.jyhs.com.servce.TranstfeSevrce;
import maven.jyhs.com.servce.impl.TranstfeSevrceImpl;
import maven.jyhs.com.util.Reflection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(urlPatterns = "/fy")
public class Fy extends HttpServlet {
    TranstfeSevrce service = CglibProxyFactory.createProxy( new TranstfeSevrceImpl());

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out = resp.getWriter();
        Map<String, Object> map = new HashMap<>();
        try {
            Sea sea = new Sea();
            Reflection.httpServletToObject(req, sea);
            service.search(sea);
            map.put("total", service.search(sea));//total 是总记录数
            map.put("data", service.getYs(Integer.parseInt(req.getParameter("page")), Integer.parseInt(req.getParameter("limit")),sea));//page 是页数 ,limit 是每页显示的记录数
            out.print(JSON.toJSONString(map));
            out.flush();
            out.close();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
        protected void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
        }
    }
